/*     */ package org.apache.commons.dbutils;
/*     */ 
/*     */ import java.sql.Connection;
/*     */ import java.sql.PreparedStatement;
/*     */ import java.sql.ResultSet;
/*     */ import java.sql.SQLException;
/*     */ import javax.sql.DataSource;
/*     */ 
/*     */ public class GenKeyQueryRunner<T> extends QueryRunner
/*     */ {
/*     */   private final int[] keyColsByIndex;
/*     */   private final String[] keyColsByName;
/*     */   private final ResultSetHandler<T> keyHandler;
/*     */   private T generatedKeys;
/*     */ 
/*     */   private GenKeyQueryRunner(DataSource ds, boolean pmdKnowBroken, int[] keyColsByIndex, String[] keyColsByName, ResultSetHandler<T> keyHandler)
/*     */   {
/*  97 */     super(ds, pmdKnowBroken);
/*  98 */     this.keyColsByIndex = keyColsByIndex;
/*  99 */     this.keyColsByName = keyColsByName;
/* 100 */     this.keyHandler = keyHandler;
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(ResultSetHandler<T> keyHandler)
/*     */   {
/* 113 */     this(null, false, null, null, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(ResultSetHandler<T> keyHandler, int[] keyColsByIndex)
/*     */   {
/* 130 */     this(null, false, keyColsByIndex, null, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(ResultSetHandler<T> keyHandler, String[] keyColsByName)
/*     */   {
/* 147 */     this(null, false, null, keyColsByName, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(DataSource ds, ResultSetHandler<T> keyHandler)
/*     */   {
/* 162 */     this(ds, false, null, null, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(DataSource ds, ResultSetHandler<T> keyHandler, int[] keyColsByIndex)
/*     */   {
/* 181 */     this(ds, false, keyColsByIndex, null, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(DataSource ds, ResultSetHandler<T> keyHandler, String[] keyColsByName)
/*     */   {
/* 200 */     this(ds, false, null, keyColsByName, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(boolean pmdKnownBroken, ResultSetHandler<T> keyHandler)
/*     */   {
/* 216 */     this(null, pmdKnownBroken, null, null, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(boolean pmdKnownBroken, ResultSetHandler<T> keyHandler, int[] keyColsByIndex)
/*     */   {
/* 235 */     this(null, pmdKnownBroken, keyColsByIndex, null, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(boolean pmdKnownBroken, ResultSetHandler<T> keyHandler, String[] keyColsByName)
/*     */   {
/* 254 */     this(null, pmdKnownBroken, null, keyColsByName, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(DataSource ds, boolean pmdKnownBroken, ResultSetHandler<T> keyHandler)
/*     */   {
/* 272 */     this(ds, pmdKnownBroken, null, null, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(DataSource ds, boolean pmdKnownBroken, ResultSetHandler<T> keyHandler, int[] keyColsByIndex)
/*     */   {
/* 293 */     this(ds, pmdKnownBroken, keyColsByIndex, null, keyHandler);
/*     */   }
/*     */ 
/*     */   public GenKeyQueryRunner(DataSource ds, boolean pmdKnownBroken, ResultSetHandler<T> keyHandler, String[] keyColsByName)
/*     */   {
/* 314 */     this(ds, pmdKnownBroken, null, keyColsByName, keyHandler);
/*     */   }
/*     */ 
/*     */   protected PreparedStatement prepareStatement(Connection conn, String sql)
/*     */     throws SQLException
/*     */   {
/*     */     PreparedStatement ps;
///*     */     PreparedStatement ps;
/* 340 */     if ((this.keyColsByIndex != null) && (this.keyColsByIndex.length > 0)) {
/* 341 */       ps = conn.prepareStatement(sql, this.keyColsByIndex);
/*     */     }
/*     */     else
/*     */     {
///*     */       PreparedStatement ps;
/* 342 */       if ((this.keyColsByName != null) && (this.keyColsByName.length > 0))
/* 343 */         ps = conn.prepareStatement(sql, this.keyColsByName);
/*     */       else {
/* 345 */         ps = conn.prepareStatement(sql, 1);
/*     */       }
/*     */     }
/* 348 */     return ps;
/*     */   }
/*     */ 
/*     */   public int update(Connection conn, String sql, Object[] params)
/*     */     throws SQLException
/*     */   {
/* 354 */     PreparedStatement stmt = null;
/* 355 */     int rows = 0;
/* 356 */     ResultSet autoKeyRs = null;
/*     */ 
/* 359 */     this.generatedKeys = null;
/*     */     try
/*     */     {
/* 362 */       stmt = prepareStatement(conn, sql);
/* 363 */       fillStatement(stmt, params);
/* 364 */       rows = stmt.executeUpdate();
/* 365 */       autoKeyRs = stmt.getGeneratedKeys();
/* 366 */       this.generatedKeys = this.keyHandler.handle(autoKeyRs);
/*     */     }
/*     */     catch (SQLException e)
/*     */     {
/* 371 */       rethrow(e, sql, params);
/*     */     }
/*     */     finally {
/*     */       try {
/* 375 */         close(autoKeyRs);
/*     */       } finally {
/* 377 */         close(stmt);
/*     */       }
/*     */     }
/*     */ 
/* 381 */     return rows;
/*     */   }
/*     */ 
/*     */   public T getGeneratedKeys()
/*     */   {
/* 391 */     return this.generatedKeys;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     org.apache.commons.dbutils.GenKeyQueryRunner
 * JD-Core Version:    0.6.1
 */